GameProductCarousel.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use client';
  2. import Link from 'next/link';
  3. import Image from 'next/image';
  4. import {
  5. Carousel,
  6. CarouselContent,
  7. CarouselItem,
  8. CarouselNext,
  9. CarouselPrevious
  10. } from '@/components/ui/carousel';
  11. import type { GameDetailProduct } from '@/types/response/store/game';
  12. export default function GameProductCarousel({ products }: { products: GameDetailProduct[] })
  13. {
  14. if (products.length === 0) {
  15. return null;
  16. }
  17. return (
  18. <section>
  19. <h2 className="mb-3 text-lg font-bold">이 게임의 상품</h2>
  20. <Carousel opts={{ align: 'start', loop: products.length > 2 }} className="w-full">
  21. <CarouselContent>
  22. {products.map(p => (
  23. <CarouselItem key={p.id} className="basis-1/2 sm:basis-1/3 lg:basis-1/4">
  24. <Link
  25. href={`/store/${p.id}`}
  26. className="flex h-full flex-col overflow-hidden rounded-lg border border-[var(--border-default)] bg-[var(--bg-elevated)] transition hover:shadow-md"
  27. >
  28. <div className="relative aspect-square w-full overflow-hidden bg-[var(--bg-elevated)]">
  29. {p.thumbnail ? (
  30. <Image src={p.thumbnail} alt={p.name} fill unoptimized sizes="200px" className="object-cover" />
  31. ) : (
  32. <span className="flex size-full items-center justify-center text-xl text-[var(--text-secondary)]">🎁</span>
  33. )}
  34. </div>
  35. <div className="flex flex-1 flex-col gap-1 p-2">
  36. <p className="line-clamp-2 text-xs">{p.name}</p>
  37. <div className="mt-auto flex items-center gap-1 text-sm font-semibold">
  38. {p.salePrice < p.price && (
  39. <span className="text-[11px] text-[var(--text-muted)] line-through">{p.price.toLocaleString()}</span>
  40. )}
  41. <span>{p.salePrice.toLocaleString()}P</span>
  42. </div>
  43. </div>
  44. </Link>
  45. </CarouselItem>
  46. ))}
  47. </CarouselContent>
  48. <CarouselPrevious aria-label="이전 상품" className="left-1 size-8 border-0 bg-black/50 text-white hover:bg-black/70 hover:text-white disabled:hidden" />
  49. <CarouselNext aria-label="다음 상품" className="right-1 size-8 border-0 bg-black/50 text-white hover:bg-black/70 hover:text-white disabled:hidden" />
  50. </Carousel>
  51. </section>
  52. );
  53. }